//
// Created by JYL on 2023-12-20.
//
#include "display_task.h"
#include "voltage_task.h"
#include "balance_task.h"
#include "filter_task.h"
#include "encoder.h"
#include "oled.h"

void Display_Task(void *argument)
{
    uint8_t str[30];
    OLED_ShowString(00,10,(u8*)"Angle");
    OLED_ShowString(0,20,(u8*)"Gyrox");
    OLED_ShowString(0,30,(uint8_t*)"L");OLED_ShowString(96,30,(u8*)"mm/s");
    OLED_ShowString(0,40,(uint8_t*)"R");OLED_ShowString(96,40,(u8*)"mm/s");
    OLED_ShowString(0,50,(u8*)"V");OLED_ShowString(30,50,(u8*)".");OLED_ShowString(64,50,(u8*)"V");
    for(;;)
    {
        OLED_Refresh_Gram();
        //printf("%.2hd,%.2hd,%.2hd,%.2f\r\n",gyro[0],gyro[1],gyro[2],angle/100.0);
        //=============第一行显示小车模式=======================//
        if(balance.Way_Angle==0)OLED_ShowString(0,0,(u8*)"DMP");
        else if(balance.Way_Angle==1)OLED_ShowString(0,0,(u8*)"Kalman");
        else if(balance.Way_Angle==2)OLED_ShowString(0,0,(u8*)"C F");

        (balance.Flag_Stop==0)?OLED_ShowString(56,0,(u8*)"ON "):OLED_ShowString(56,0,(u8*)"OFF");
        sprintf((char *)str,"M=%4.1f",myabs((int)(balance.Middle_angle*10))/10.0f);
        OLED_ShowString(80,0,str);
        //=============第二行显示角度=======================//
        (mpu6050.Angle_Balance<0?OLED_ShowString(48,10,(u8*)"-"):OLED_ShowString(48,10,(u8*)"+"));
        OLED_ShowNumber(56,10, myabs((int)mpu6050.Angle_Balance),3,12);
        //=============第三行显示角速度与距离===============//
        (mpu6050.Gyro_Balance<0?OLED_ShowString(42,20,(u8*)"-"):OLED_ShowString(42,20,(u8*)"+"));
        OLED_ShowNumber(50,20, myabs((int)mpu6050.Gyro_Balance),4,12);
//        //=============第四行显示左编码器PWM与读数=======================//
        (Motor_Left<0?OLED_ShowString(16,30,(u8*)"-"):OLED_ShowString(16,30,(u8*)"+"));
        OLED_ShowNumber(26,30,myabs((int)Motor_Left),4,12);
        (balance.Velocity_Left<0?OLED_ShowString(60,30,(u8*)"-"):OLED_ShowString(60,30,(u8*)"+"));
        OLED_ShowNumber(68,30,myabs((int)balance.Velocity_Left),4,12);
//        //=============第五行显示右编码器PWM与读数=======================//
        (Motor_Right<0?OLED_ShowString(16,40,(u8*)"-"):OLED_ShowString(16,40,(u8*)"+"));
        OLED_ShowNumber(26,40,myabs((int)Motor_Right),4,12);
        (balance.Velocity_Right<0?OLED_ShowString(60,40,(u8*)"-"):OLED_ShowString(60,40,(u8*)"+"));
        OLED_ShowNumber(68,40,myabs((int)balance.Velocity_Right),4,12);
        //=============第六行显示电压与电机开关=======================//
        sprintf((char *)str,"V=%4.1fv %3.0f%% %.1f",adc.battery_voltage,(adc.electricity_percentage),adc.Resister);
        OLED_ShowString(0,50,str);
//        printf("%.2f,%.2f\r\n",mpu6050.Angle_Balance,mpu6050.Gyro_Balance);
        //osDelay(100);
        osDelay(100);
    }
}
